package com.gxy.learn.design.model.behaviour.iterator;

import lombok.extern.slf4j.Slf4j;

/**
 * @description: 迭代器模式测试
 * @author: gaoxueyong
 * @Date: 2022/11/8 21:47
 */
@Slf4j
public class Client {
    public static void main(String[] args) {
//        创建迭代器
        StudentAggregateImpl studentAggregate = new StudentAggregateImpl();
//        添加对象
        studentAggregate.addStudent(new Student("张三","001"));
        studentAggregate.addStudent(new Student("李四","002"));
        studentAggregate.addStudent(new Student("王二","003"));
        studentAggregate.addStudent(new Student("麻子","004"));

//        获取迭代器
        StudentIterator studentIterator = studentAggregate.getStudentIterator();
//        遍历集合
        while (studentIterator.hasNext()){
            Student next = studentIterator.next();
            log.info("student = {}",next.toString());
        }
    }
}
